package com.etc;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAspect {
    // *任意返回类型包括void
    // *任意类
    // *任意方法
    // (..) 任意参数
    @Pointcut("execution(* com.etc..pojo.*.*(..))")
    public void abc() {
    }

    @Before("abc()")
    public void befor(JoinPoint point) {
        System.out.println(point.getTarget());
        System.out.println("--befor 1块钱 ");
    }
    @Around("abc()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println(point.getTarget());
        Object o = null;
        try {
            System.out.println("--around befor: 1块--");
            o = point.proceed(); // 所有的方法都会执行
            System.out.println("--around after: 1块-----");
        } catch (Exception e) {
            System.out.println("--around excpetion: 1块-----");
        } finally {
            System.out.println("--around finally: 1块-----");
        }
        return o;
    }

}
